package com.itacademy.cinnamonreader.fragments;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;

public class MyFragmentPagerAdapter extends FragmentPagerAdapter
				implements ViewPager.OnPageChangeListener {
	
		static final String TAG = "myLogs";
		private final int pageCount;
		private final ViewPager mViewPager;
		
		
		public MyFragmentPagerAdapter(FragmentActivity activity,ViewPager pager, int pageCount) {
	      super(activity.getSupportFragmentManager());
	      this.pageCount=pageCount;
	      this.mViewPager=pager;
	      this.mViewPager.setAdapter(this);
	      this.mViewPager.setOnPageChangeListener(this);
	    }
		//listeners methods
		@Override
	      public void onPageSelected(int position) {
	        Log.d(TAG, "onPageSelected, position = " + position);
	      }

	      @Override
	      public void onPageScrolled(int position, float positionOffset,
	          int positionOffsetPixels) {
	      }

	      @Override
	      public void onPageScrollStateChanged(int state) {
	    	 
	      }
	      
	      //FragmentPagerAdapters methods
	    @Override
	    public Fragment getItem(int position) {
	    	switch (position){
	    	case 0:
	    		return new FeedsFragment();
	    	case 1:
	    		return new ItemListFragment();
	    	default: 
	    		return new FeedsFragment();
	    	}
	      
	    }

	    @Override
	    public int getCount() {
	      return this.pageCount;
	    }
	    
	    @Override
	    public CharSequence getPageTitle(int position) {
	    	switch(position){
	    	case 0: return "Feeds";
	    	case 1:	return "Items";
	    	case 2:	return "Something else";
	    	default: return "";
	    	}
	    }
	  }

